package org.uoss.applications.framework.dao.impl;

import org.uoss.applications.framework.dao.IGeneralObjectDAO;
import org.uoss.applications.framework.dao.jpa.AbstractDAO;
import org.uoss.applications.framework.dao.model.QueryModel;
import org.uoss.applications.framework.dao.model.ResultSetModel;
import org.uoss.applications.framework.entity.GeneralObject;
import org.uoss.applications.framework.exception.DAOException;
import org.uoss.core.exception.UOSSException;

public class GeneralObjectDAOImpl<T extends GeneralObject> extends  AbstractDAO<T> implements IGeneralObjectDAO<T> {

	@Override
	public void addGeneralObject(T object) throws DAOException {
		try {
			this.getGenericDAO().persist(object);
		} 
		catch (UOSSException e) {
			e.printStackTrace();
		}
	}

	@Override
	public void deleteGeneralObject(T object) throws DAOException {
		try {
			this.getGenericDAO().delete(object);
		} 
		catch (UOSSException e) {
			e.printStackTrace();
		}
	}

	@Override
	public ResultSetModel<T> getResultSetByPaging(Class<T> entityObject,QueryModel query) throws DAOException {
		ResultSetModel<T> result = null;
		try {
			result = this.getGenericDAO().searchByHQL("from " + entityObject.getName(), query);
		} 
		catch (UOSSException e) {
			e.printStackTrace();
		}
		return result;
	}

	@Override
	public void updateGeneralObject(T object) throws DAOException {
		try {
			this.getGenericDAO().update(object);
		} 
		catch (UOSSException e) {
			e.printStackTrace();
		}
	}
}
